from typing import List

class Solution:
    def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:
        ans, min = -1 , float('inf')
        for i in range(len(points)):
            xi, yi = points[i]
            if xi == x or yi == y:
                d = abs(xi - x) + abs(yi - y)
                if (d < min):
                    min = d
                    ans = i
        return ans